package com.WFinstitute.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.WFinstitute.domain.User;
import com.WFinstitute.service.UserService;
/**
 * 
 * @author 匹夫
 * @date 2016-7-23 下午8:44:14
 * @function
 */
@Controller
@RequestMapping("/user")
public class UserController {
	
	@Resource
	private UserService  userService;
	
	/**
	 * 【后台页面】修改密码
	 * @param response
	 * @param request
	 * @return
	 */
	@RequestMapping("/updatepwd")
	public String updatepwd(HttpServletResponse response,HttpServletRequest request){
        String oldpassword=request.getParameter("oldpassword");
		String password=request.getParameter("password");
		User user=(User)request.getSession().getAttribute("user");
		if(user==null){
			return "/WEB-INF/backstage/login.jsp";
		}
		if(!user.getPassword().equals(oldpassword)){
			request.setAttribute("errorText", "原密码不正确!");
			return "/WEB-INF/backstage/editpwd.jsp";
		}
		user.setPassword(password);
		userService.updateUser(user);
		request.setAttribute("errorText", "密码修改成功!");
		return "/WEB-INF/backstage/editpwd.jsp";

	}

}
